package com.binance.feign.ribbon.exception;

import feign.Response;
import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeException;

import java.io.ByteArrayInputStream;
import java.net.URI;

/**
 * Created by Fei.Huang on 2018/9/7.
 */
public class RibbonResponseStatusCodeException extends RetryableStatusCodeException {
    private Response response;

    public RibbonResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) {
        super(serviceId, response.status(), response, uri);
        this.response = Response.builder().body(new ByteArrayInputStream(body), body.length)
                .headers(response.headers()).reason(response.reason())
                .status(response.status()).request(response.request()).build();
    }

    @Override
    public Response getResponse() {
        return response;
    }
}